package com.xiaobai.inter;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class InterTest {
    public static void main(String[] args) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IntrospectionException {
        User user = new User();
        user.setAge(11);
        user.setName("abc");
        user.setdTSGggg("jkDfff125dd");
        Field[] fields = user.getClass().getDeclaredFields();

        for (Field field : fields) {
            Column column = field.getAnnotation(Column.class);
            if (column == null) {
                continue;
            }
            field.setAccessible(true);
            System.out.println(field.get(user));
            if (field.getGenericType() == String.class) {
                if (column.upper()) {
//                    field.set(user, field.get(user).toString().toUpperCase());
                    PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), User.class);
                    Method method = descriptor.getWriteMethod();
                    method.invoke(user, field.get(user).toString().toUpperCase());
                }
            }
            System.out.println(field.get(user));


        }
    }
}
